<?php

namespace Mage\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Acme\UserBundle\Helper\UploadHandler;
use Acme\PersonBundle\Entity\Personimage;
use Acme\PinnwandBundle\Entity\Pinnwand;
use Acme\PinnwandBundle\Entity\Pinnwandgalerie;
use Doctrine\ORM\EntityRepository;

// these import the "@Route" and "@Template" annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Validator\Constraints\DateTime;

/**
 * @Route("/admin")
 */
class SecurityController extends Controller {
	
	/**
	 * @Route("/login", name="_security_start")
	 * @Template()
	 */
	public function loginAction() {
		$request = $this->getRequest ();
		
		// echo $request->getUri(); exit;
		
		$session = $request->getSession ();
		// get the login error if there is one
		if ($request->attributes->has ( SecurityContext::AUTHENTICATION_ERROR )) {
			$error = $request->attributes->get ( SecurityContext::AUTHENTICATION_ERROR );
		} else {
			$error = $session->get ( SecurityContext::AUTHENTICATION_ERROR );
			$session->set ( SecurityContext::AUTHENTICATION_ERROR, '' );
		}
		
		return array (
				'last_username' => $request->getSession ()->get ( SecurityContext::LAST_USERNAME ),
				'error' => $error 
		);
	}
	
	/**
	 * @Route("/login_check", name="_secure_check")
	 */
	public function securityCheckAction() {

	}
	
	
	/**
	 * @Route("/logout", name="_secure_logout")
	 */
	public function logoutAction() {
		// The security layer will intercept this request
	}
	
	
}